package com.nicho.controller;

import java.util.Scanner;

import com.nicho.pojo.Student;
import com.nicho.service.StudentService;
import com.nicho.util.MD5;
import com.nicho.view.StudentPage;

/*
 * @Author: 姜东浩
 * @Date: 2021-11-11 14:38:48
 * @LastEditors: 姜东浩
 * @LastEditTime: 2021-11-12 13:54:04
 * @Description: 学生控制器类
 */
public class StudentController {

    Student student = null;
    StudentService studentService = new StudentService();
    Scanner sc = new Scanner(System.in);

    /**
     * @description: 学生登录
     * @param {String} userId
     * @param {String} password
     * @author: 姜东浩
     */
    public void login(String userId, String password) {

        // 将传进来的账号密码封装为一个学生对象
        student = new Student(userId, password);

        // 登录成功显示首页视图，否则提示登陆失败
        if (studentService.studentLogin(student) != null) {
            StudentPage.showLoginSuccess();
        } else {
            System.out.println("登录失败");
        }

    }

    /**
     * @description: 修改学生密码
     * @return 修改密码操作结束后的对应提示信息
     * @author: 姜东浩
     */
    public String updatePassword() {

        System.out.print("请输入新密码：");
        return studentService.updatePassword(MD5.md5(sc.next()));

    }

    /**
     * @description: 学生选课
     * @param {*}
     * @return 添加操作结束后的提示信息
     * @author: 姜东浩
     */
    public String chooseCourse() {

        studentService.printMap(studentService.chooseCourseMap());
        System.out.println("退出请输入：exit");
        System.out.print("请输入要选择的课程号：");
        String usc = sc.next();
        if (usc.equals("exit")) {
            return "";
        }
        if (studentService.getMapValue(studentService.chooseCourseMap(), usc) == -1) {
            return "课程不存在";
        }
        if (studentService.hadThisCourse(usc) == 1) {
            return "您已选过该课程，请选择其他课程";
        }
        return studentService.chooseCourse(usc);

    }

    /**
     * @description: 学生删课
     * @return 移除操作结束后的提示信息
     * @author: 姜东浩
     */
    public String deleteCourse() {

        studentService.printMyCourseList(studentService.getMyCourseList());
        System.out.println("退出请输入：exit");
        System.out.print("请输入要选择的课程号：");
        String usc = sc.next();
        if (usc.equals("exit")) {
            return "";
        }
        if (studentService.hadThisCourse(usc) == -1) {
            return "未选此门课程";
        }
        return studentService.deleteCourse(usc);

    }

    /**
     * @description: （全部信息）打印自己的选课集合
     * @author: 姜东浩
     */
    public void printMyCourseListAM() {

        studentService.printMyCourseListAM(studentService.getMyCourseList());

    }

    /**
     * @description: （重要信息）打印自己的选课集合
     * @author: 姜东浩
     */
    public void printMyCourseList() {

        studentService.printMyCourseList(studentService.getMyCourseList());

    }

}